/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-5-22 下午12:37 Created by dwzhang
 */
package com.jade.bss.api.controller;

import java.util.HashMap;
import javax.servlet.http.HttpServletResponse;

import com.jade.framework.base.vfile.VFileConstants;
import com.jade.framework.base.vfile.VFileUtils;
import com.jade.framework.base.util.ResponseUtils;
import com.jade.modules.software.Software;
import com.jade.modules.software.SoftwareUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 软件控制器。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-5-22 下午12:37
 */
@Controller
@RequestMapping (value = "/software")
public class SoftwareController
{
    @RequestMapping (value = "/checkVersion.json")
    public void checkVersion(@RequestParam (value = "type") String type,
                             @RequestParam (value = "version", required = false) String version,
                             HttpServletResponse response)
            throws Exception
    {
        Software software = SoftwareUtils.getNewestSoftware(type);
        HashMap result = new HashMap();
        result.put("update", false);
        if (software != null) {
            if (version.compareToIgnoreCase(software.getVersion()) < 0) {
                result.put("update", true);
            }
            result.put("version", software.getVersion());
            result.put("remark", software.getRemark());
            result.put("url", VFileUtils.getVFileURI(VFileConstants.DATA_TYPE_SOFTWARE, software.getFilePath()));
        }
        ResponseUtils.writeSuccessResult(response, result);
    }

}
